using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using JGSY.CMS.LowCode.Platform.Application.DTOs;

namespace JGSY.CMS.LowCode.Platform.Application.Interfaces
{
    /// <summary>
    /// 权限路由映射服务接口
    /// 提供路由权限映射的集中管理和热更新功能
    /// </summary>
    public interface IPermissionRouteMappingService
    {
        /// <summary>
        /// 获取所有活跃的路由映射
        /// </summary>
        Task<IEnumerable<PermissionRouteMappingDto>> GetActiveAsync();
        
        /// <summary>
        /// 获取分页的路由映射列表
        /// </summary>
        Task<(List<PermissionRouteMappingDto> items, int total)> GetPagedAsync(
            int pageIndex = 1, 
            int pageSize = 20, 
            string? group = null, 
            bool? isActive = null,
            string? search = null);
        
        /// <summary>
        /// 根据ID获取路由映射
        /// </summary>
        Task<PermissionRouteMappingDto?> GetByIdAsync(long id);
        
        /// <summary>
        /// 创建路由映射
        /// </summary>
        Task<long> CreateAsync(PermissionRouteMappingDto dto);
        
        /// <summary>
        /// 更新路由映射
        /// </summary>
        Task UpdateAsync(long id, PermissionRouteMappingDto dto);
        
        /// <summary>
        /// 删除路由映射
        /// </summary>
        Task DeleteAsync(long id);
        
        /// <summary>
        /// 批量删除路由映射
        /// </summary>
        Task BatchDeleteAsync(IEnumerable<long> ids);
        
        /// <summary>
        /// 根据路径和方法解析权限代码
        /// </summary>
        Task<string?> ResolvePermissionAsync(string path, string method);
        
        /// <summary>
        /// 批量解析权限代码
        /// </summary>
        Task<Dictionary<string, string>> BatchResolvePermissionsAsync(
            IEnumerable<(string path, string method)> requests);
        
        /// <summary>
        /// 获取所有分组
        /// </summary>
        Task<IEnumerable<string>> GetGroupsAsync();
        
        /// <summary>
        /// 验证路径模式是否有效
        /// </summary>
        bool ValidatePathPattern(string pattern);
        
        /// <summary>
        /// 检查是否存在冲突
        /// </summary>
        Task<bool> HasConflictAsync(string path, string method, long? excludeId = null);
        
        /// <summary>
        /// 导入配置文件中的映射
        /// </summary>
        Task<int> ImportFromConfigurationAsync(bool replaceExisting = false);
        
        /// <summary>
        /// 导出为JSON配置
        /// </summary>
        Task<string> ExportAsJsonAsync(string? group = null);
        
        /// <summary>
        /// 从JSON导入映射
        /// </summary>
        Task<int> ImportFromJsonAsync(string json, bool replaceExisting = false);
        
        /// <summary>
        /// 获取统计信息
        /// </summary>
        Task<PermissionRouteMappingStatisticsDto> GetStatisticsAsync();
        
        /// <summary>
        /// 刷新缓存（触发热更新）
        /// </summary>
        Task RefreshCacheAsync();
        
        /// <summary>
        /// 测试路径匹配
        /// </summary>
        Task<IEnumerable<PermissionRouteMappingDto>> TestMatchAsync(string path, string method);
    }
}
